def check(l1, r1, l2, r2, candy):
    global ans
    for i in candy[l1 : r1 + 1]:
        for j in candy[l2 :  r2 + 1]:
            if i == j:
                ans += 1
    return ans

n = int(input())
candy = [0] + list(map(int, input().split()))
q = int(input())
for _ in range(q):
    l1, r1, l2, r2 = map(int, input().split())
    ans = 0
    print(check(l1, r1, l2, r2, candy))